package com.kaisu.blog.web.result.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * @author kaisu
 */
@Data
@Schema(description = "分页VO")
public class PageVO<T> {
    /**
     * 数据
     */
    @Schema(description = "数据")
    private List<T> data;
    /**
     * 页码
     */
    @Schema(description = "页码")
    private Integer page;
    /**
     * 数量
     */
    @Schema(description = "数量")
    private Integer size;
    /**
     * 总数
     */
    @Schema(description = "总数")
    private Long total;
    /**
     * 总页
     */
    @Schema(description = "总页")
    private Integer pageTotal;

    public static <T> PageVO<T> of(Page<T> page) {
        PageVO<T> vo = new PageVO<>();
        vo.setData(page.getContent());
        vo.setPage(page.getNumber() + 1);
        vo.setSize(page.getSize());
        vo.setTotal(page.getTotalElements());
        vo.setPageTotal(page.getTotalPages());
        return vo;
    }


}
